package com.tarena.lbs.basic.web.controller;

import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.basic.web.service.AreaService;
import com.tarena.lbs.pojo.basic.vo.AreaVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
public class AreaController {
    @Autowired
    private AreaService areaService;
    //查询 省级列表
    @GetMapping("/admin/basic/area/queryList")
    public Result<List<AreaVO>> provinces(){
        Integer parentId = 0;
        List<AreaVO> vos = areaService.getChildren(parentId);
        return new Result<>(vos);
    }
    //查询省 或 市的下一级列表
    @GetMapping("/admin/basic/area/{parentId}/children")
    public Result<List<AreaVO>> children(@PathVariable("parentId") Integer parentId){
        return new Result<>(areaService.getChildren(parentId));
    }
    //一次性查询所有行政区域数据 封装成树结构返回
    @GetMapping("/admin/basic/area/tree")
    public Result<List<AreaVO>> tree(){
        return new Result<>(areaService.tree());
    }
}
